import http from "./http.js"
import md5 from "js-md5"
// 注册接口
export function register(name,psd){
    return http.post("/user/register",{
        loginName:name,
        password:psd
    })
}
// 登录接口
export function login(name,psd){
    return http.post("/user/login",{
        loginName:name,
        passwordMd5:md5(psd),
    })
}
// 首页数据
// http://backend-api-01.newbee.ltd/api/v1/index-infos
export function index_infos(){
    return http.get("/index-infos")
}
// 根据商品id 获取详情页数据
// http://backend-api-01.newbee.ltd/api/v1/goods/detail/10925
export function goodsDetail(id){
    return http.get("/goods/detail/" +id)
}
// 添加商品到购物车
// http://backend-api-01.newbee.ltd/api/v1/shop-cart
export function addGoods(number,id){
    return http.post("/shop-cart",{
        goodsCount:number,
        goodsId:id
    })
}
// 将商品的具体数据添加到购物车
export function addGoodsList(){
    return http.get("/shop-cart")
}
// 删除购物车数据接口
// http://backend-api-01.newbee.ltd/api/v1/shop-cart/54593
export function delCart(id){
    return http.delete("/shop-cart/"+id)
}
// 购物车步进器的实现
// http://backend-api-01.newbee.ltd/api/v1/shop-cart/54593
export function changeCount(cartId,Count){
    return http.put("/shop-cart/",{
        cartItemId:cartId,
        goodsCount:Count,
    })
}
// 地址管理
// http://backend-api-01.newbee.ltd/api/v1/address
export function addressList(){
    return http.get("/address")
}
// 根据id获取地址数据 实现回显
// http://backend-api-01.newbee.ltd/api/v1/address
export function addressDetail(id){
    return http.get("/address/"+id)
}
//编辑地址后 更新地址
export function updateAddress(obj){
    return http.put("/address",obj)
}
// 新增地址
// http://backend-api-01.newbee.ltd/api/v1/address
export function addressAdd(obj){
    return http.post("/address",obj)
}
// 删除地址
export function removeAddress(id){
    return http.delete("/address/"+id)
}
// 获取生成订单的接口
// http://backend-api-01.newbee.ltd/api/v1/shop-cart/settle?cartItemIds=55698,55699
export function getOrderGoods(ids){
    return http.get("/shop-cart/settle?cartItemIds="+ids)
}
// 生成订单接口
// http://backend-api-01.newbee.ltd/api/v1/saveOrder
export function newOrder(addressId,cartItemIds){
    return http.post("/saveOrder",{addressId,cartItemIds})
}
// 生成订单接口
// http://backend-api-01.newbee.ltd/api/v1/order?pageNumber=1&status=
export function getOrderList(pageNumber,status=''){
    return http.get("/order",{
        params:{
            pageNumber,
            status
        }
    })
}